<?php
$ac='16ucom';
$pw='c33367701511b4f6020ec61ded352059';
$s= new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

$txt=file_get_contents('php://input');
logfile(date('Y-m-d H:i:s')."---".$txt,'terminal_log.txt');

// $txt = '{"VerifyCode":"551cf0247bef54ad6ee31e2195da313a","Order16U":"995637","OrderCall":"OTA03722015041600002","Tnumber":"1","OrderState":1,"ActionTime":"2015-04-16 16:34"}';

$array = json_decode($txt,true);
$Order16U=  $array['Order16U'];//票付通订单号
$actiontime = $array['ActionTime'];//验证时间
$Tnumber = $array['Tnumber']; //消费数量
$VerifyCode = $array['VerifyCode'];
// print_R($Order16U);exit;
$sign = md5($Order16U.'123');

if($VerifyCode == $sign){
	$o=$s->Order_Globle_Search(
											"", "", "", "", "",
											"", "", "", "", "",
											"", "", $Order16U, "", "", 
											"", "", "", 1, 1, 
											0, 1, 0, 0, "",
											0, "", 0, '', '', 
											'', 0, "",	"", "", "" 	
										);
	$os=simplexml_load_string($o);
	$UUsalerid = (string)$os->Rec->UUsalerid;
	$UUcode = (string)$os->Rec->UUcode;
	$UUstatus = (int)$os->Rec->UUstatus;
	$UUlid = (int)$os->Rec->UUlid;
	if($UUlid !=7641){	
		$smg = '{"istrue":"false1","Order16U":"'.$Order16U.'","sms":"不是青岛海底世界的订单"}';
		$return = iconv("UTF-8","GB2312//IGNORE",$smg);
		echo $return;
		exit;
	}
	if($UUstatus == 0){
		$r=$s->Terminal_Check_In($UUsalerid,$UUcode,$actiontime,"");
		$r_xml = simplexml_load_string($r);
		$r_order = $r_xml->Rec->UUordernum;
		if($r_order == $Order16U){
			$smg = '{"istrue":"false","Order16U":"'.$Order16U.'","sms":"验证成功"}';
			$return = iconv("UTF-8","GB2312//IGNORE",$smg);
			echo $return;
			exit;
		}else{
			$smg = '{"istrue":"false4","Order16U":"'.$Order16U.'","sms":"验证失败"}';
			$return = iconv("UTF-8","GB2312//IGNORE",$smg);
			echo $return;		
		}
	}else{
		$smg = '{"istrue":"false2","Order16U":"'.$Order16U.'","sms":"订单状态出错"}';
		$return = iconv("UTF-8","GB2312//IGNORE",$smg);
		echo $return;
	}
}else{
	$smg = '{"istrue":"false3","Order16U":"'.$Order16U.'","sms":"签名不通过"}';
	$return = iconv("UTF-8","GB2312//IGNORE",$smg);
	echo $return;
}

function logfile($txt,$path){
	$fp = fopen($path,"a");
	flock($fp, LOCK_EX) ;
	fwrite($fp,$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp); 
}
?>